package com.example.adapter;

import java.io.IOError;
import java.util.ArrayList;

import com.example.android.ArticleTest;
import com.example.androidtest.R;
import com.example.fragment.Person_Fragment;

import android.R.raw;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MyAdapterTest extends PagerAdapter {
	ArrayList<ArticleTest> list = new ArrayList<>();
	Person_Fragment person;
	private String result;
	private Handler handler;
	private String url = "http://www.mengxianyi.net/one/homepage.json";
	private TextView textView_title;
	private TextView textView_author;
	private TextView textView_content;
	private Context context;//上下文 承接
	public MyAdapterTest(Context context,ArrayList<ArticleTest> list) {//解析后的数据传递过来
		this.list = list;
		this.context = context;
	}

	@Override

	public int getCount() {
		// TODO Auto-generated method stub
		return list != null&&list.size()>0? list.size():0;//判断传来的解析后获取的数据 有没有内容 可以判断有没有传过来解析的数据
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0 == arg1;
	}

	@Override
	public View instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		View view = LayoutInflater.from(context).inflate(R.layout.article, null);
//		handler = new Handler(new Handler.Callback() {
//
//			@Override
//			public boolean handleMessage(Message msg) {
//				if (msg.what == 100) {
//					result = (String) msg.obj;
//				}
//				return false;
//			}
//		});
//		new MyThreadTest(handler, url);
		
		
//		View view = list.get(position);
		textView_title =(TextView)view.findViewById(R.id.tv_article_title);
		textView_author =(TextView)view.findViewById(R.id.tv_article_author);
		textView_content =(TextView)view.findViewById(R.id.tv_article_connect);
		ArticleTest bean = list.get(position);
		textView_author.setText(bean.getAuthor());
		textView_content.setText(bean.getContent());
		textView_title.setText(bean.getTitle());
		container.addView(view);

		return view;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
	}
}
